﻿/*
 * Class that can save a CaSaveContainer to a file. The saved data can be retrieved by using the LoadCa.cs class.
 * Author: Anders Høst | ahkj@itu.dk
 * date: 11 dec 2011
 */
using System;
using System.Diagnostics.Contracts;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using AutomaTones.Model.Automaton_Model;
using AutomaTones.Model.Utils;

namespace AutomaTones.Model.Tools {
    /// <summary>
    /// Intends to serialize the Cellular Automaton passed in and save it with the associated name.
    /// Does not ensure any result of the operation
    /// </summary>
    public static class SaveCa {
        public static void Save(CaSaveContainer caSaveContainer, String nameOfFile)
        {
            Contract.Requires(caSaveContainer != null);
            Contract.Requires(nameOfFile.Length>0);
            Stream s = File.Open(nameOfFile, FileMode.Create);
            BinaryFormatter bf = new BinaryFormatter();
             bf.Serialize(s, caSaveContainer);
            s.Close();
        }
    }
}
